THE AUTHOR ASSUMES NO RESPONSIBILITY FOR ANY LOSS OR DAMAGE SUSTAINED BY THE USE OR MISUSE OF THIS SOFTWARE AND MANUAL. CAVEAT EMPTOR.
•Introduction
••What is this all about?
The fractal lab kit is a command driven system for generating and investigating fractal images. It is written using Chris Heilman's Pocket Forth , a small Forth interpreter for the Macintosh. Pocket Forth is available via anonymous FTP from _archive.umich.edu_ in the directory /mac/development/languages/.
The kit consists of a set of Forth words that allow the user to easily create fractals based on IFS mappings. Because of it's small size and generality, it should run on virtually all Macintosh computers. By entering simple commands the user can define maps, draw the resultant fractals in a variety of colors, show the orientation of the mappings, measure positions within the image, and zoom in to view details. Fractals using up to seven maps may be generated.
••Why not create a standard Macintosh application for all of this?
I used Forth for two reasons. First, I am still learning the language and thought that this would be a good project towards that end. Secondly, I have used several fractal programs in the past and while they are excellent at what they do, they are rigid and inflexible. Creating a system like this in Forth seemed ideal. Forth is fast and highly interactive. It is also small and very easily extended. Not only does the user have all the fractal commands, but they also have all of Forth still at their disposal. A little programming can quickly extend the existing capabilities. Pocket Forth was my choice for several reasons, primarily, it is free and can be freely distributed, as well as supporting floating point numbers to make life easier.
Kudos to Dr. Bruce Craven, University of Melbourne, Australia, for all his helpful comments and suggestions for improving the program. Kudos also
to Mr. Stephen Gard, Australia, for his thorough testing of and enthusiam for the program!
Fractal Lab Kit is freeware, if you use it and have any suggestions or comments please let me know at the addresses below. I have plans for additional `modules' for investigating Mandelbrot and Julia sets, biomorph images, and chaos in one and two dimensions. Your feedback will encourage me to continue. Even if you have no specific comment, let me know where you are so I can follow the program. I prefer postcards, but email is good too.
Ron Kneusel
8725 West Burdick Ave
Milwaukee, WI 53227
USA
kneusel@msupa.pa.msu.edu
or
rtk@herman.gem.valpo.edu
•Fractals and IFS: an overview
A fractal is a geometric object with a non-integer dimension. We are used to thinking in terms of Euclidean geometry, that is, in terms of points, lines, areas (surfaces), and volumes (solids). Fractals do not easily fit in such a framework and are difficult to comprehend (at least for me). Common geometrical objects have integer dimensions:
Object Dimension
=====================
point 0
line 1
plane 2
solid 3
but fractals have non-integer dimensions, like 0.63... etc. How can this be you say? Let's look at the simplest fractal of them all, the Cantor set.
To create the Cantor set imagine a line of length 1. Now, remove the middle third of that line. Remove the middle third of the two remaining lines. Continue removing the middle third an infinite number of times. When you are finished the object you will be left with is a fractal with a dimension that is not 0 (it's not a point) but is less than 1 (a line from 0 to 1 would contain all points, clearly a cantor set does not) and it can be shown that the final dimension is ln2/ln3 = 0.6309297536.....
••Derivation of the Cantor Set dimension
One possible definition of dimension, the self-similar dimension, is the ratio of the natural log of the number of intervals N (in 1-d) of length beta needed to completely cover the set to the natural log of the reciprocal of beta, taken in the limit that beta -->∞. In the case of the Cantor set beta=(1/3)^n where n is the `level' of the set. (Check: the second level has two sections of length 1/3 while the next level has four sections of length 1/9 = (1/3)^2) So the condition beta -->∞ becomes n -->∞ . Also, for the Cantor set, the number of intervals to cover the set at the level n is N=2^n. (Check: at the second level there are 2^1 = 2 intervals, at the third level there are 2^2=4 intervals and so on.) So we write:
The Cantor set, like other purely mathematical fractals, is completely self-similar. That is, it looks identical on different scales (actually it is independent of scale). Take a piece of paper (you do have scrap paper near the computer, don't you?) and draw the first few lines of the Cantor set, one below the other:
If you look at what you have just drawn you will notice that if you magnify a lower level it will look like one above it, the entire set is made up of an infinite number of copies of itself. (Infinity shows up frequently when talking about fractals.) As this is a simple fractal it is not terribly interesting; the program draws more complex fractals where life is a little more exciting.
They are definitely odd, but fractals do turn up in many places in nature, the nautilus shell (see the SPIRAL), your lungs and circulatory system (see the TREE), etc. Some people even think that the distribution of matter in the universe is a fractal.
••What about fractals and chaos?
Fractals are often mentioned in connection with chaotic behavior of dynamical systems. The link comes from the fact that the final attractor (a strange attractor) of a dissipative dynamical system is a fractal object (sometimes). If you want to talk more about this, contact me at the above address.
•What is IFS?
IFS (Iterated Function System) is the means by which the program generates images. It was developed by Michael Barnsley. IFS involves defining a number of maps that in some way determine what the final product will look like (more on that later). An initial point is chosen (the origin is nice) and iterated (i.e. put it in - get something out - put that something back in, etc.) . These are maps in the mathematical sense - roughly, a way of transforming a collection of points into another space or back into its own space as is the case here. The map used for each iteration is chosen at random based on the assigned probability, the higher the probability the more likely that map is to be chosen. After each iteration the resulting point is plotted. As this process is continued the fractal image is built. Changing the probability of a map can dramatically affect the resulting image, so it might take a bit to get the picture `just right'.
In mathematical terms a 2 dimensional map is most easily represented in matrix form. A matrix is similar to the two dimensional arrays used in many programming languages. If we have a starting point (x,y) and we want to find the transformed coordinates, (x',y'), we can write the transformation in this way:
This is equivalent to writing two equations:
The 2x2 matrix controls the reorientation of the initial coordinate system while the vector (e f) is an offset to a new origin point for the map.
••Finding the `magic' numbers for an IFS transformation
By way of example, I will show how to find the matrix values that generate what has become known as the Mandelbrot Dragon. While the dragon is usually generated according to a prescription (like the Cantor set above) it can also be found using two mappings (i.e. two matrices).
Recalling that a fractal is made up of an infinite number of copies of itself, we need only specify the `first' copy and the IFS algorithm will fill in the rest. Therefore, imagine a square from 0 to 1, this is the starting point as it were. We must transform the points from this square into a different square (or squares), where the number of transformations equals the number of `parts' that make up the fractal. The dragon consists of two parts: a contracted 45 degree rotation of the coordinate axes and a contracted -45 degree rotation (with a flip). Perhaps the best way to imagine this is to picture an arrow: ------------\from 0 to 1, the head of the arrow is only a half head so we can see if there is a flip as well as a rotation and translation. After some thought we realize that we need something like the following to generate the dragon:
Again take a piece of paper and draw a 2 inch arrow as above, the head ofthe arrow is on the right and the barb is pointing north. Now, draw another arrow from the left edge of the first going at a 45 degree angle until it intersects an imaginary line running north to south that passes through the midpoint of the first line. Draw the barb of this arrow on the left side of the right endpoint of this line. Finally, complete the triangle and draw the barb of this arrow on the left side and touching the head of the second arrow. When you are finished you will have something like this:
where the directions of the arrow heads are indicated. Finally, complete each of the three squares defined by the arrows as one edge.
Now comes the fun part, how do we change the drawing into the numbers for the maps? To find the maps we need to solve, for each map, two systems of three linear equations since there are six numbers to find. To write the six equations we must know where at least three points of the original square (the one from 0 to 1) map to in the new maps. This is where the arrow head directions become important. The arrow determines two points for us, the head and the tail, while the last point can be either of the two corners of the original square and where they map to in the final square. So, to this end, label the tail and head of the first arrow drawn (a1,a2) and (b1,b2) respectively, and label the corner of the square above (a1,a2) as (c1,c2). These are the original three points, now label the corresponding points in the second square (the one at a positive 45 degree angle to the first) as (A1,A2) for the tail (in this case they are the same point) and (B1,B2) for the head. Label the farthest left corner of the square (C1,C2).
Once this is done, we can write the following six equations to determine the first map:
A1 = a1*a + a2*b + e
B1 = b1*a + b2*b + e
C1 = c1*a + c2*b + e
and
A2 = a1*c + a2*d + f
B2 = b1*c + b2*d + f
C2 = c1*c + c2*d + f
In order to get actual numbers we need to impose a coordinate system. Draw an x and y axis where the first arrow goes from 0 to 1 on the x axis and left edge of the first square goes from 0 to 1 on the y axis. In this coordinate system, (a1,a2)=(0,0); (b1,b2)=(1,0); (c1,c2)=(0,1) and the points for thefirst map are (A1,A2)=(0,0); (B1,B2)=(0.5,0.5); (C1,C2)=(-0.5,0.5). The values for the matrix and vector are found by solving the two systems. Cramer's rule allows the solutions to be written as:
Where the vertical lines represent the determinant. There exists a corresponding set for the c, d, and f values. With these we find that the transformations are:
I will leave the actual solution as an exercise for the reader.
The last thing to consider is what sort of probability we want to assign to each of these maps. Since there is no reason to favor one map to another we can in this case get away with a probability of 0.5 for each (remember, probabilities should add to 1). This is not always the case, though.
There are many good books on fractals and chaos at all levels, check the local book store or library. The book {\em Chaos: The Making of a New Science} by John Gleik is a good place to start, though it is lean on the technical aspect.
••Getting Started
The IFS module includes the Fractal Lab Kit application and the documentation, demo and maps folders. The program starts in interactive mode (i.e. in Forth). There is a mouse driven shell that you may use to adjust the settings and drawing, to use it enter shell at the prompt. See _Using the Shell_ for more information. The examples in the _Tutorial_ do not use the shell.
The _Maps_ folder contains definitions for several fractals courtesy of Dr. Dale Snider, UW-Milwaukee Department of Physics. Use _Open_ under the _File_ menu to load the maps. To use, enter the map name and the word 'draw'.
The _Demo_ folder contains a color and black & white version of 'Cathedral' which draws a cathedral using fractals. Examine the source code (in Forth) to see how it works. Unfortunately, it works best on large screens... sorry Classic and SE users!
The commands you enter are really just Forth words. In fact, you are really using Pocket Forth with the IFS words predefined, however, you need not be familiar with Forth to use the program.
••Setting up for Different Sized Monitors
Upon startup Fractal Lab Kit will get the size of the main monitor's screen and set the application window accordingly. However, the drawing parameters will be preset only if the screen is 512 x 342, 512 x 384, or 640 x 480 pixels. If you use a different sized monitor you will need to adjust the screen origin to make the most use of it as Fractal Lab Kit will set up for a 512 x 384 pixel screen if it does not recognize one of the above monitor sizes.
If you are using a monitor other than the main monitor you will also need to adjust the screen origin with the word {\tt screen} to move the drawing region onto the secondary monitor. By default, the main monitor is used.
•Tutorial
••A Sample Session
In this sample session.
«after double-clicking the Fractal Lab Kit icon»
ok_ open
«choose the IFS-Maps file from the standard Mac open dialog»
ok_ fern green color on outlines draw
«program loads the maps for the fern, draws the outlines of the maps, waits for a keypress, and draws the fern in green until the user presses a key»
ok_ mouse
«program shows the true coordinates of the mouse pointer until the user presses a key»
ok_ settings
Current plot origin ( 0.00000 , 0.00000 ) \hfil \break
Current screen origin ( 100 , 330 ) \hfil \break
Current x \& y scale is 1.0000 : 1.0000 \hfil \break
Axes are currently OFF \hfil \break
Draw Outlines is currently ON \hfil \break
Current number of maps = 5 \hfil \break
ok_ off outlines 0.178 0.034 origin .25 range cdraw
«program zooms in to the second leaflet and generates a magnified image using a different color for each map until a keypress»